package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xianbeiying.app.ckgl.R;

/**
 * 实时信息数据适配
 */
public class RealTimeInfoAdapter extends BaseAdapter{
    private Context context;
    private String[] typename={"空气温度","空气湿度","土壤温度","土壤湿度","光照强度","二氧化碳","用水统计"};
//    private float[] id={0,90,180,270,360,-90,-180};
//    private float[] id={0,15,30,45,60,75,90};
//    private int [] id={90,105,120,135,150,165,180};
    private int [] imgView={R.mipmap.tw,R.mipmap.ty,R.mipmap.tw,R.mipmap.ty,R.mipmap.gz,R.mipmap.co2,R.mipmap.water};
    private String [] x={"℃","RH","℃","RH","Lux","ppm","m³"};
    private int [] xdata;
    public RealTimeInfoAdapter(Context context,int [] xdata) {
        this.context = context;
        this.xdata=xdata;
    }
    @Override
    public int getCount() {
        return typename.length+1;
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_real_time_info, parent, false);
            holder = new ViewHolder();
            holder.ly_gjingjie=(LinearLayout) convertView.findViewById(R.id.ly_gjingjie);
            holder.ly_djingjie=(LinearLayout) convertView.findViewById(R.id.ly_djingjie);
            holder.real_name=(TextView) convertView.findViewById(R.id.real_name);
            holder.tv_real_time=(TextView) convertView.findViewById(R.id.tv_real_time);
            holder.real_img_zj=(ImageView) convertView.findViewById(R.id.real_img_zj);
            holder.real_img=(ImageView) convertView.findViewById(R.id.real_img);
            holder.rl_real_time=(RelativeLayout) convertView.findViewById(R.id.rl_real_time);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(position==typename.length){
            holder.ly_gjingjie.setVisibility(View.VISIBLE);
            holder.ly_djingjie.setVisibility(View.VISIBLE);
            holder.rl_real_time.setVisibility(View.GONE);
            holder.tv_real_time.setVisibility(View.GONE);
        }else{
            holder.tv_real_time.setVisibility(View.VISIBLE);
            holder.rl_real_time.setVisibility(View.VISIBLE);
            holder.ly_gjingjie.setVisibility(View.GONE);
            holder.ly_djingjie.setVisibility(View.GONE);
            holder.real_name.setText(typename[position]);
            holder.real_img.setImageResource(imgView[position]);
            holder.tv_real_time.setText(xdata[position]+x[position]);
            //x轴选转
        }

        return convertView;
    }
    private class ViewHolder{
        RelativeLayout rl_real_time;
       LinearLayout ly_gjingjie,ly_djingjie;
       TextView tv_real_time,real_name;
       ImageView  real_img_zj,real_img;
    }
}
